package com.example.weizix.ui.activity;

import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.text.Spanned;
import android.text.TextUtils;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.weizix.R;
import com.example.weizix.base.BaseActivtiy;
import com.example.weizix.bean.NewsDetailBean;
import com.example.weizix.presenter.NewsDetaiPresenter;
import com.example.weizix.view.NewsDetaiView;

import butterknife.BindView;

public class NewsDetailActivity extends BaseActivtiy<NewsDetaiPresenter> implements NewsDetaiView {



    @BindView(R.id.toolBar)
    Toolbar mToolBar;
    @BindView(R.id.appBar)
    AppBarLayout mAppBar;
    @BindView(R.id.cdl)
    CoordinatorLayout mCdl;
    @BindView(R.id.iv)
    ImageView mIv;
    @BindView(R.id.ctl)
    CollapsingToolbarLayout mCtl;
    @BindView(R.id.html_text)
    TextView tv;
    private int name;

    @Override
    protected NewsDetaiPresenter initPresenter() {
        return new NewsDetaiPresenter();
    }



    @Override
    protected void initData() {
        //因为新闻的详情主题,后端给的是html的一部分,所以展示的时候不能使用列表
        //1.webView
        //2.Spanned spanned = Html.fromHtml("html"); 拿Textview设置
        //3.开源WebView,开源Textview

        mPresenter.getNewsDetail(name);
    }

    @Override
    protected void initView() {
        name = getIntent().getIntExtra("name", 0);

        setSupportActionBar(mToolBar);

        //标题必须在CollapsingToolbarLayout设置
        mCtl.setTitle("折叠ToolBar");
        //扩张时候的title颜色
        mCtl.setExpandedTitleColor(getResources().getColor(R.color.colorAccent));
        //收缩后显示title的颜色
        mCtl.setCollapsedTitleTextColor(getResources().getColor(R.color.btn_pressed_green_solid));
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_news_detail;
    }

    @Override
    public void setData(NewsDetailBean newsDetailBean) {
        //
        mCtl.setTitle(newsDetailBean.getTitle());
        Glide.with(this).load(newsDetailBean.getImage()).into(mIv);
        String body = newsDetailBean.getBody();
        if (!TextUtils.isEmpty(body)){
            Spanned spanned = Html.fromHtml(body);
            tv.setText(spanned);
        }
    }

    @Override
    public void showToast(String msg) {

    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }
}
